package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.domain.QuestionReply;
import cn.wolfcode.trip.base.query.QuestionQueryObject;
import cn.wolfcode.trip.base.service.IQuestionReplyService;
import cn.wolfcode.trip.base.service.IQuestionService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 *问题达人资源过滤器
 * */
@RestController
@RequestMapping("/questions")
public class QuestionController {

    @Autowired
    private IQuestionService questionService;
    @Autowired
    private IQuestionReplyService ReplyService;

    /**
     * 查询所有问题
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo queryForQuestionList(QuestionQueryObject qo){
        PageInfo<Question> pageInfo = questionService.queryForQuestionList(qo);
        return pageInfo;

    }

    /**
     * 查询当前问题
     * @param qo
     * @return
     */
    @GetMapping("/{questionId}")
    public Question queryForReplyList(QuestionQueryObject qo){
        Question detail = questionService.queryForReply(qo);
        return detail;

    }
    /**
     * 查询当前问题的回复内容
     * @param qo
     * @return
     */
    @GetMapping("/{questionId}/{answers}")
    public PageInfo queryForAnswerList(QuestionQueryObject qo){
        PageInfo<Question> reply = ReplyService.queryForQuestionReply(qo);
        return reply;

    }

    /*
     * 添加问题
     * @param question
     * @return
     */
    @PostMapping("/asks")
    public JsonResult saveQuestion(Question question){
        questionService.save(question);
        return new JsonResult();

    }
    /*
     * 添加回复
     * @param qo
     * @return
     */
    @PostMapping("/reply")
    public JsonResult saveReply(QuestionReply qo){
        ReplyService.save(qo);
        return new JsonResult();

    }

}
